<script setup lang="ts">
import { FileUpload } from "@/components/common/FileUpload";
import { ref } from "vue";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    finalFiles: "",
    finalResult: "",
    finalResultFiles: "",
    masterUserId: "",
    masterUserName: "",
    userIds: [],
    shenMasterName: "",
    shenPartName: "",
    firstAccountDate: "",
    secondAccountDate: "",
    score: null,
    writeObjective: "",
    writeObjectiveFiles: ""
  }),
  userList: null
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="160px"
    class="mr-12"
  >
    <el-form-item label="平台名称" prop="finalResult">
      <el-input
        v-model="newFormInline.finalResult"
        placeholder="请输入"
        class="!w-[300px]"
      />
    </el-form-item>
    <el-form-item label="平台级别" prop="writeObjective">
      <el-select
        v-model="newFormInline.writeObjective"
        placeholder="请选择"
        clearable
        class="!w-[300px]"
      >
        <el-option label="国家级" value="国家级" />
        <el-option label="省部级" value="省部级" />
        <el-option label="市厅级" value="市厅级" />
        <el-option label="校级" value="校级" />
        <el-option label="其他" value="其他" />
      </el-select>
    </el-form-item>
    <el-form-item label="申报负责人" prop="masterUserId">
      <el-select
        v-model="newFormInline.masterUserId"
        clearable
        filterable
        placeholder="请选择"
        class="!w-[300px]"
      >
        <el-option
          v-for="item in props.userList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="申报参与人" prop="userIds">
      <el-select
        v-model="newFormInline.userIds"
        clearable
        filterable
        multiple
        placeholder="请选择"
        class="!w-[300px]"
      >
        <el-option
          v-for="item in props.userList"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
    </el-form-item>

    <el-form-item label="申报日期" prop="firstAccountDate">
      <el-date-picker
        v-model="newFormInline.firstAccountDate"
        type="date"
        placeholder="请选择"
        value-format="YYYY-MM-DD"
        class="!w-[300px]"
      />
    </el-form-item>

    <el-form-item label="获批日期" prop="secondAccountDate">
      <el-date-picker
        v-model="newFormInline.secondAccountDate"
        type="date"
        placeholder="请选择"
        value-format="YYYY-MM-DD"
        class="!w-[300px]"
      />
    </el-form-item>

    <el-form-item label="通知文件" prop="writeObjectiveFiles">
      <FileUpload v-model="newFormInline.writeObjectiveFiles" :limit="10" />
    </el-form-item>
    <el-form-item label="申报文件" prop="finalResultFiles">
      <FileUpload v-model="newFormInline.finalResultFiles" :limit="10" />
    </el-form-item>
    <el-form-item label="获批文件" prop="finalFiles">
      <FileUpload v-model="newFormInline.finalFiles" :limit="10" />
    </el-form-item>
    <el-form-item label="积分" prop="score">
      <el-input-number
        v-model="newFormInline.score"
        :min="0"
        placeholder="请输入"
        class="!w-[200px]"
      />
    </el-form-item>
  </el-form>
</template>
